/**
 *  Document   : Authentication
 *  Created on : 26 juil. 2008, 18:21:04
 *  Author     : Rivo
 */

package gla.centralhotel.business;

import gla.centralhotel.dao.interfaces.IAgencyDAO;
import gla.centralhotel.dao.interfaces.IManagerDAO;
import gla.centralhotel.exception.IllegalAuthenticationException;
import gla.centralhotel.model.Agency;
import gla.centralhotel.model.Manager;
import javax.ejb.EJB;
import javax.ejb.Stateless;

@Stateless
public class Authentication implements IAuthentication {
    @EJB
    private IAgencyDAO agencyDAO;
    @EJB
    private IManagerDAO managerDAO;
    
    /**
     * Authentification de l'utilisateur (gestionnaire)
     * @param manager
     * @return
     * @throws gla.centralhotel.exception.IllegalAuthenticationException
     */
    public Manager connectManager(String email, String pwd)throws IllegalAuthenticationException{
        
        try{
            return managerDAO.findManagerByEmailPassword(email, pwd);
        }catch(IllegalAuthenticationException noR){
            noR.printStackTrace();
            throw new IllegalAuthenticationException("Aucun utilisateur trouvé!");
        }
    }
    
    /**
     * Authentification de l'utilisateur (Agence)
     * @param email
     * @param pwd
     * @return
     * @throws gla.centralhotel.exception.IllegalAuthenticationException
     */
    public Agency connectAgency(String email, String pwd) throws IllegalAuthenticationException {
        try{
            return agencyDAO.findAgencyByEmailPassword(email, pwd);
        }catch(IllegalAuthenticationException ex){
            throw new IllegalAuthenticationException("Aucun utilisateur trouvé!");
        }
    }
}
